﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DynamicProperties.Tests
{
	[TestClass]
	public class DefaulValue_ValueTypeTests
	{
		DynamicProperty<object, int> testValuePropertyNoDefault = new DynamicProperty<object, int>("Value, No default");
		DynamicProperty<object, int> testValuePropertyDefaultDirect = new DynamicProperty<object, int>("Value, Default direct", 1/*default*/);
		DynamicProperty<object, int> testValuePropertyDefaultFunc = new DynamicProperty<object, int>("Value, Default func", () => 2/*default*/);
		
		[TestMethod]
		public void DefaultValueTypeNoDefault()
		{
			// check if default value is correct
			var obj1 = new object();
			Assert.AreEqual(0, testValuePropertyNoDefault.Get(obj1));
		}

		[TestMethod]
		public void DefaultValueTypeDefaultDirect()
		{
			// check if default value is correct
			var obj1 = new object();
			Assert.AreEqual(1, testValuePropertyDefaultDirect.Get(obj1));
		}

		[TestMethod]
		public void DefaultValueTypeDefaultFunc()
		{
			// check if default value is correct
			var obj1 = new object();
			Assert.AreEqual(2, testValuePropertyDefaultFunc.Get(obj1));
		}

		[TestMethod]
		public void DefaultValueTypeNoDefaultWithReset()
		{
			// check if value is set back to default value after reset
			var obj1 = new object();
			testValuePropertyNoDefault.Set(obj1, 10);
			Extender.Global.ResetObject(obj1);
			Assert.AreEqual(0, testValuePropertyNoDefault.Get(obj1));
		}

		[TestMethod]
		public void DefaultValueTypeDefaultDirectWithReset()
		{
			// check if value is set back to default value after reset
			var obj1 = new object();
			testValuePropertyDefaultDirect.Set(obj1, 10);
			Extender.Global.ResetObject(obj1);
			Assert.AreEqual(1, testValuePropertyDefaultDirect.Get(obj1));
		}

		[TestMethod]
		public void DefaultValueTypeDefaultFuncWithReset()
		{
			// check if value is set back to default value after reset
			var obj1 = new object();
			testValuePropertyDefaultFunc.Set(obj1, 10);
			Extender.Global.ResetObject(obj1);
			Assert.AreEqual(2, testValuePropertyDefaultFunc.Get(obj1));
		}
	}
}
